<?php
/**
 * Created by PhpStorm.
 * User: huliren<huliren0516@163.com>
 * Date: 2017/9/27
 * Time: 11:33
 */
require('../../../common.inc.php');

define('SITE_AUTH', 'mobile-app-version-manage');

use lib\core\AdminAction;
use Tools\RedisKeyCache as Model;

class versionManage extends AdminAction
{
    private $list_url = 'data/modules/mobile/versionManage.php';

    public function doDefault()
    {
        $smarty = $this->app->page();

        $version_info = Model::getReviewVersion();
        $code_info = Model::getLoginByCode();
        if (empty($code_info)) {
            $code_info = 0;
        }

        $smarty->value('version_info', $version_info);
        $smarty->value('code_info', $code_info);
        $smarty->output('mobile/versionManage_list.tpl');
    }


    public function doAdd()
    {
        $version = trim($_POST['version']);
        $res = Model::setReviewVersion($version);
        if ($res) {
            HDshowMsg('操作成功!', ['url' => $this->list_url]);
        } else {
            HDshowMsg('操作失败!', ['url' => $this->list_url, 'type' => 0]);
        }
    }

    public function doUpdataByCode()
    {
        $code = intval($_POST['code']);
        if ($code) {
            $rel = Model::setLoginByCode(0);
        } else {
            $rel = Model::setLoginByCode(1);
        }
        if ($rel) {
            if($code){
                $this->output(['type' => 'yes','rel'=>0]);
            }else{
                $this->output(['type' => 'yes','rel'=>1]);
            }
        }

    }
}

$app->run();